package com.atguigu.util.homework2;

/**
 * @author caesar
 * @date 2025/7/4
 * @apiNote
 */
public class ArrayUtils {
    public static void sort(int[] arr) {
        for(int i =1 ;i<arr.length;i++){
            for(int j = 0;j<arr.length-i;j++){
                if(arr[j]>arr[j+1]){
                    int t = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = t;
                }
            }
        }
    }
    public static void sort(double arr[]){
        for(int i = 1;i<arr.length;i++){
            for(int j = 0;j<arr.length-i;j++){
                if(arr[j]>arr[j+1]){
                    double t = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = t;
                }
            }
        }
    }
    public static void sort(char arr[]){
        for(int i = 1;i<arr.length;i++){
            for(int j = 0;j<arr.length-i;j++){
                if(arr[j]>arr[j+1]){
                    char t = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = t;
                }
            }
        }
    }

    public static String toString(int[] arr){
        String str = "[";
        for(int i = 0;i<arr.length;i++){
            if(i == arr.length-1){
                str += arr[i];
            }else{
                str += arr[i] + ",";
            }
        }
        str += "]";
        return str;
    }
    public static String toString(double[] arr){
        String str = "[";
        for(int i = 0;i<arr.length;i++){
            if(i == arr.length-1){
                str += arr[i];
            }else{
                str += arr[i] + ",";
            }
        }
        str += "]";
        return str;
    }
    public static String toString(char[] arr){
        String str = "[";
        for(int i = 0;i<arr.length;i++){
            if(i == arr.length-1){
                str += arr[i];
            }else{
                str += arr[i] + ",";
            }
        }
        str += "]";
        return str;
    }
}
